Ruby For Kids For Dummies by Christopher Haupt

Ruby For Kids For Dummies by Christopher Haupt

Author:Christopher Haupt
Language: eng
Format: epub
ISBN: 9781119055990
Publisher: Wiley
Published: 2015-09-08T00:00:00+00:00


Define an empty array for the bundle: bundle = []

Now fill the array with new Straw objects: 1.upto(short) do

bundle << Straw.new(SHORT_STRAW)

end

You’ve created a loop that will go as many times as the count inside the short variable. The << syntax is one way to add an object to an array. Here you’re creating a new Straw object, setting its size to the value in the SHORT_STRAW constant, and then adding that object to the array.

Write another loop for the long straws using the exact same technique: 1.upto(long) do

bundle << Straw.new(LONG_STRAW)

end

You’re adding the long straws to the end of the existing array.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.